<%-- 
    Document   : index
    Created on : Dec 10, 2009, 6.36 pm
    Author     : Shiva
    
    /WEB-INF/jspf/admin/sidebar.jspf
    /WEB-INF/jspf/admin/sidebar.jspf
	/WEB-INF/jspf/admin/notice.jspf    
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<%@ page import="java.util.Vector" %>
<%@ page import="jhu.profiteer.data.Commodity" %>
<%@ page import="jhu.profiteer.data.CommodityJpaController" %>

<html>
  <%
    String pageTitle = "Commodity Information";
    String cssFile = "/profiteer-game/css/profiteer.css";
  %>
  <%@ include file="/WEB-INF/jspf/admin/header.jspf" %>
  <body>
    <%@ include file="/WEB-INF/jspf/title.jspf" %>
    <div class="contentArea Body">
      <div class="pagetitle">Airplane Information</div>
      <div class="pagebody">
        <table>
          <tr>
            <td id="menu"><%@ include file="/WEB-INF/jspf/menu.jspf" %></td>
            <td>
              <div class="divround">
                <%@ include file="/WEB-INF/jspf/admin/notice.jspf" %>
                <%
                  // look for commodityId in request
                  String commID = request.getParameter("commodityId");

                  if(null == commID) // no commodity
                  {
                    if(null == notices) notices = new Vector<String>();
                    notices.add("No Commodity chosen.");
                    this.getServletContext()
                            .getRequestDispatcher("/characterInformation")
                            .forward(request, response);
                  }

                  // convert commodity ID to long
                  Long lngCommID = 0L;

                  try
                  {
                    lngCommID = Long.parseLong(commID.trim());
                  }
                  catch(NumberFormatException nfe)
                  {
                    if(null == notices) notices = new Vector<String>();
                    notices.add("No Commodity chosen.");
                    this.getServletContext()
                            .getRequestDispatcher("/characterInformation")
                            .forward(request, response);
                  }
		
                  // commodityID found in request & able to convert to long
                  CommodityJpaController jc = new CommodityJpaController();
                  Commodity c = jc.findCommodity(lngCommID);
                  String commName;
                  String commDesc;

                  if (null == c) // commodity not found
                  {
                    if(null == notices) notices = new Vector<String>();
                    notices.add("No Commodity found for the given commodity ID.");
                    this.getServletContext().getRequestDispatcher("/characterInformation")
                            .forward(request, response);
                    return;
                  }
                  else // commodity found
                  {
                    commName = c.getName();
                    commDesc = c.getDescription();
                  }
                %>
                <p>
                  Name :
                  <strong><%= commName %></strong>
                  <br/>
                </p>
                <p>
                  Description :
                  <strong><%= commDesc %></strong>
                  <br/>
                </p>
              </div>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <%@ include file="/WEB-INF/jspf/footer.jspf" %>
  </body>
</html>